package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.app.API;
import com.kbbywyclient.data.model.RetrievePassWordOneModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.RetrievePwdOneContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Observer;

/**
 * Description:
 * Created by FHW
 * on 2017/4/1
 */

public class RetrievePwdOnePresenter extends BasePresenter implements RetrievePwdOneContract.Presenter {
    private RetrievePwdOneContract.View view;
    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil rsaJsonUtil;

    @Inject
    public RetrievePwdOnePresenter(RetrievePwdOneContract.View view) {
        this.view = view;
    }


    @Override
    public String getPicCodeUrl(String ImgToken) {
        return API.PIC_CODE + "?ImgToken=" + ImgToken;
    }

    @Override
    public void getForgetPassWordOne(String UserName, String ImgToken, String Code) {
        rsaJsonUtil.put("UserName", UserName);
        rsaJsonUtil.put("ImgToken", ImgToken);
        rsaJsonUtil.put("Code", Code);
        view.showLoadingDialog(mContext.getString(R.string.text_loading));
        ApiServiceHelper.
                appointThreadNormal(apiService.getRetrievePassWordOne(rsaJsonUtil.getRsaParams())).
                subscribe(new Observer<RetrievePassWordOneModel>() {
                    @Override
                    public void onCompleted() {
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        HttpExcUtil.printError(e);
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onNext(RetrievePassWordOneModel retrievePassWordOneModel) {
                        view.loadSucOne(retrievePassWordOneModel.getData());
                    }
                });
    }
}
